package Main.Latex;

import java.util.ArrayList;
import java.util.List;

public class Composite extends Component{
    public List<Component> components = new ArrayList<>();

    public void addChild(Component child){
        components.add(child);
    }

    public List<Component> getChilds(){
        return components;
    }

    @Override
    public String getLexString() {
        StringBuilder stringBuilder = new StringBuilder();

        //前缀
        for(String prefix : preContents){
            stringBuilder.append(prefix);
        }

        //子组件
        for (Component child : components){
            stringBuilder.append(child.getLexString());
        }

        //后缀
        for (String sufContents : sufContents){
            stringBuilder.append(sufContents);
        }

        return stringBuilder.toString();
    }
}
